<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>jsFactory Test Example</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <script type="text/javascript" language="javascript1.7" src="../jsfactory.js"></script>
    <!-- load the person object for testing -->
    <script type="text/javascript" language="javascript1.7" src="person.js"></script>
    <!-- load the test fixures that we need -->
    <script type="text/javascript" language="javascript1.7" src="test_fixture.js"></script>
</head>
<body>
    <div id="factory_lists"><!-- setting an HTML div for a test below--></div>
<script>
    // This is just a simple little test runner to see jsFactory work rather quickly
    // out of a test runner. You can include in any you want.
    // So defining a few assertion here.
    function assertEquals(expected, result) {
        if (expected != result) {
            document.write("Expected: " + expected + ", but found: " + result + "<br />");
        } else {
            document.write("Test Passed<br />");
        }
    }

    function assertTrue(result) {
        if (result != true) {
            document.write("Expected True but found: " + result + "<br />")
        } else {
            document.write("Test Passed<br />");
        }
    }
</script>
<script>

function testPersonFixture() {
    // Build the Person object with predefined fixure data
    var person = jsFactory.create("Person")

    //Testing to make sure that it was set up correctly
    assertEquals("Scott", person.FirstName())
    assertEquals("Krutsinger", person.LastName())
}

function testPersonSpecialSetup() {
    // Build the Person object with predefined fixure data
    var person = jsFactory.create("Person", {"_firstName" : "Marvin"})

    //Testing to make sure that it was set up correctly
    assertEquals("Marvin", person._firstName)
    assertEquals("Krutsinger", person._lastName)
}

function testAddingHtmlElementsWithFactory() {

    // Create two checkboxes and attach to factory_lists div
	var element1 = jsFactory.createHtmlElement("input", {id : "factory_input_1", type : "checkbox", name : "factory_input_1", checked : false}, "factory_lists");
	var element2 = jsFactory.createHtmlElement("input", {id : "factory_input_2", type : "checkbox", name : "factory_input_2", checked : false}, "factory_lists");

	document.getElementById("factory_input_1").checked = true
    document.getElementById("factory_input_2").checked = true

	assertTrue(document.getElementById("factory_input_1").checked);
	assertTrue(document.getElementById("factory_input_2").checked);
}

testPersonFixture()
testPersonSpecialSetup()
testAddingHtmlElementsWithFactory()
 </script>
</body>
</html>
